Sorting II (2)
- Merge Sort
- Recursive call, then merge
- For merge
- Extract size
- Extract item
- Merge
- Reassign item
- All condition for resiging/extracting should follow less than equal format
- (
l>r) condition may causes infinitie recursion, use (l>=r) instead. - Left half is
[l...m]and right half is[m+1...r]
- Recursive Bubble Sort
- Set the termination condition properly (at begin)
- Replace the outer loop with recursive call (at end, can work before loop as well)
- Recursive Insertion Sort
- Just replace the outer loop with one paramter
- Quick Sort
- 10 April, 2026: 00.23.32 ❌
-
Failed at implmentation
- Kind of reverse approach of merge, get partitioned inex, recursive call based on the partition index
- Place the pivot at right place
Step Low High Subarray Pivot Pivot Index After Partition Array State After Step 1 0 6 [8, 3, 1, 7, 0, 10, 2] 2 2 [1, 0, 2, 7, 8, 10, 3] 2 0 1 [1, 0] 0 0 [0, 1, 2, 7, 8, 10, 3] 3 3 6 [7, 8, 10, 3] 3 3 [0, 1, 2, 3, 8, 10, 7] 4 4 6 [8, 10, 7] 7 4 [0, 1, 2, 3, 7, 10, 8] 5 5 6 [10, 8] 8 5 [0, 1, 2, 3, 7, 8, 10]
-
- 10 April, 2026: 00.23.32 ❌